<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03猜数字</title>
</head>
<body>
<button onclick="alert('警告信息！')">测试警告框</button>
<button onclick="confirm('你确定要关闭吗？')">测试确认框</button>
<button onclick="prompt('请输入验证码')">测试输入框</button>
<h1>已生成一个1~100之间的随机数:</h1>
<input type="text" placeholder="请输入你猜的数字">
<button onclick="guess()">点我验证</button>
<h1>小提示:<span></span></h1>
<script>
    let r = parseInt(Math.random()*100)+1;
    console.log("打个小抄："+r);
    let count = 0;
    function guess(){
        let n = document.querySelector("input").value;
        if(isNaN(n)){
            alert('请输入数字!');
            return;
        }
        let spanE = document.querySelector("span");
        count++;
        if(n>r){
            spanE.innerHTML ="猜大了!";
        }else if(n<r){
            spanE.innerHTML ="猜小了";
        }else{
            spanE.innerHTML ="恭喜你用了"+count+"次就猜对了!";
        }
    }
</script>
</body>
</html>